package com.eliza.base.views.component.resources

import androidx.compose.animation.graphics.ExperimentalAnimationGraphicsApi
import androidx.compose.animation.graphics.res.animatedVectorResource
import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter
import androidx.compose.animation.graphics.vector.AnimatedImageVector
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Menu
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import com.eliza.base.R

@Preview(showBackground = true)
@Composable
fun ResourcesScreenPre() {
    ResourcesScreen(rememberNavController())
}

@Composable
fun ResourcesScreen(navController: NavController) {
    Column(
        modifier = Modifier
            .fillMaxWidth()
    ) {
        textResource()
        dimenResource()
        iconResource()
//        iconAnimateResource()
    }

}

@Composable
private fun textResource() {
    Text(
        text = stringResource(R.string.app_auth)
    )
    Text(
        text = stringResource(R.string.app_auth, "New Year", 2021)
    )
//    Text(
//        text = pluralStringResource(
//            R.plurals.runtime_format,
//            1,
//            1
//        )
//    )
}

@Composable
private fun dimenResource() {
    val smallPadding = dimensionResource(R.dimen.external_padding)
    Text(
        text = stringResource(R.string.app_auth),
        modifier = Modifier.padding(smallPadding)
    )
}

@Composable
private fun iconResource() {
    Icon(
        painter = painterResource(id = R.drawable.ic_launcher),
        contentDescription = null // decorative element
    )
    Icon(Icons.Rounded.Menu, contentDescription = "Localized description")
}

@OptIn(ExperimentalAnimationGraphicsApi::class)
@Composable
private fun iconAnimateResource() {
    val image =
        AnimatedImageVector.animatedVectorResource(R.drawable.ic_launcher)
    val atEnd by remember { mutableStateOf(false) }
    Icon(
        painter = rememberAnimatedVectorPainter(image, atEnd),
        contentDescription = null // decorative element
    )
}
